package com.kyhd.audio.service;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kyhd.audio.dao.AudioExchangeLogRepository;
import com.kyhd.audio.dao.model.AudioExchangeLog;
import com.kyhd.audio.dao.model.Novel;

@Service
public class AudioExchangeLogService {
	
	@Autowired
	AudioExchangeLogRepository audioExchangeLogRepository;

	public AudioExchangeLog save(Novel novel, String path) {
		AudioExchangeLog audioExchangeLog = new AudioExchangeLog();
		audioExchangeLog.setContentNovelId(novel.getContent_novel_id());
		audioExchangeLog.setContentId(novel.getContent_id());
		audioExchangeLog.setPath(path);
		audioExchangeLog.setCtime(DateTime.now());
		audioExchangeLog = this.audioExchangeLogRepository.save(audioExchangeLog);
		return audioExchangeLog;
	}
	
	public AudioExchangeLog getByNovelIdAndContentId(String novelId, String contentId) {
		AudioExchangeLog audioExchangeLog = null;
		if(novelId!=null&&contentId!=null) {
			audioExchangeLog = this.audioExchangeLogRepository.getByNovelIdAndContentId(novelId, contentId);
		}
		return audioExchangeLog;
	}
	
}
